<template>
  <common-list>
    <common-search slot="search" @search="handleQuery" @reset="resetQuery">
      <el-form
        @submit.native.prevent
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        label-width="65px"
      >
        <el-form-item label="脆弱性名称" prop="name">
          <common-input
            :verify="false"
            v-model="queryParams.name"
            @enter="handleQuery"
            clearable
          />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select v-model="queryParams.status">
            <el-option label="全部" :value="null"></el-option>
            <el-option label="启用" :value="0"></el-option>
            <el-option label="停用" :value="1"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </common-search>
    <common-table slot="content" v-loading="loading" :data="list">
      <el-table-column
        label="脆弱性名称"
        prop="name"
        align="left"
        fixed
        show-overflow-tooltip
      />
      <el-table-column
        label="描述"
        align="left"
        prop="remark"
        show-overflow-tooltip
      />
      <el-table-column label="状态" align="center" width="100px">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.status === 0">启用</el-tag>
          <el-tag type="danger" v-else-if="scope.row.status === 1">停用</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="left" width="60" fixed="right">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="handleShake(scope.row)"
            :disabled="scope.row.isDisabledForShake"
          >
            {{ scope.row.interfaceSwitch === 0 ? "停用" : "启用" }}
          </el-button>
        </template>
      </el-table-column>
    </common-table>
    <pagination
      slot="pagination"
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </common-list>
</template>

<script>
import { formatDate } from "@/utils";
import BaseList from "@/mixins/BaseList";

export default {
  name: "index",
  mixins: [BaseList],
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      list: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        status: null,
      },
      form: {},
    };
  },
  created() {
    this.getList();
  },

  methods: {
    /** 查询执行历史列表 */
    getList() {
      this.loading = true;
      // queryPageList(this.queryParams)
      //   .then((res) => {
      //     if (res && res.code === 200) {
      //       this.list = res.data.dataList;
      //       this.total = res.data.totalCount;
      //     } else {
      //       this.list = [];
      //       this.total = 0;
      //     }
      //   })
      //   .finally(() => (this.loading = false));
    },
    /** 查询按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = this.$options.data().queryParams;
      this.$refs.commonDept.clearDept();
    },
  },
};
</script>
